home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: seebs@solutions.solon.com (Peter Seebach)
- Newsgroups: comp.lang.c
- Subject: Re: reversing a string
- Date: 6 Apr 1996 14:19:40 -0600
- Organization: Usenet Fact Police (Undercover)
- Message-ID: <4k6jks$fh9@solutions.solon.com>
- References: <4k6cjl$j8f@central.server.swt.edu>
- Reply-To: seebs@solon.com
- NNTP-Posting-Host: solutions.solon.com
-
- In article <4k6cjl$j8f@central.server.swt.edu>,
- Leland Newsom <ln16674@nyssa.swt.edu> wrote:
- >I have a challenge from a friend of mine. He wanted me to reverse a string
- >with recursion without using any additional variables or loops. I got mine
- >to work by using exclusive or, but I needed an additional variable. Can
- >someone help with this problem without using the additional variable?
-
- It's trivial with something like
- void rev (char *s) {
- if (*s) {
- rev(s + 1);
- putchar(*s);
- }
- }
- but this is not, strictly speaking, fair, as you're using external state
- anyway.
-
- I can't see a way to reverse in place without a temporary of some sort,
- or a loop of some sort, or something which is fundementally equivalent
- to one of those. There may be one, but I don't know it.
-
- -s
- --
- Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
- C/Unix wizard -- C/Unix questions? Send mail for help. No, really!
- FUCK the communications decency act. Goddamned government. [literally.]
- The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.html
-